
import axios from 'axios'
import ElementUI from 'element-ui'
axios.defaults.headers["Content-Type"] = "application/json;charset=UTF-8";
const fetch = axios.create({
    baseURL: "http://localhost:3000/"
})
fetch.interceptors.request.use(function (config) {

    config.headers['Authorization'] = localStorage["token"];
    console.log("请求拦截器" + JSON.stringify(config))
    return config;

}, function (error) {
    return Promise.reject(error);
})
fetch.interceptors.response.use((response) => {
    console.log("响应拦截器" + JSON.stringify(response))
    console.log(response.status);
    // 响应成功，根据后台返回数据统一处理错误码
    switch (response.data.code) {
        case 200:
            console.log("是200啊")
            ElementUI.Message({
                message: "登录成功！",
                type: 'warning'
            });
            break;
        case 500:
            // 提示内容及操作
            ElementUI.Message({
                message: "服务端报500错误",
                type: 'warning'
            });
            break;
        // 更多状态提示...
    }
    return response;
}, (error) => {
    // 响应失败
    return Promise.reject(error);
})


export default fetch;